package itdfq.ydd.Creational_Pattern.jiandangongchang;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;

public class XMLUtilFurit {
    public static String getName(){
        try {
            DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = dFactory.newDocumentBuilder();
            Document doc;
            doc=builder.parse(new File("src/itdfq/ydd/jiandangongchang/configFruit.xml"));
            NodeList nl = doc.getElementsByTagName("name");
            Node firstChild = nl.item(0).getFirstChild();
            String name = firstChild.getNodeValue().trim();
            return name;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
